home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / helper / source / snd.c < prev    next >
Text File  |  1991-10-18  |  4KB  |  200 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <snd.h>
  5. #include    <mos.h>
  6.  
  7. #define    TRUE    1
  8. #define    FALSE    0
  9. #define    ERR    (-1)
  10.  
  11. extern char    swork[];
  12.  
  13. char    *getins(env,file)
  14. char    *env,*file;
  15. {
  16.     static char tmp[128];
  17.     char *p;
  18.  
  19.     if ( (p = getenv(env)) == NULL )
  20.     return NULL;
  21.     sprintf(tmp,"%s\\%s",p,file);
  22.     return tmp;
  23. }
  24. char    *xopen(char *file)
  25. {
  26.     FILE    *fp;
  27.     long    fsz;
  28.     char    *buf;
  29.     register MEM_FP  *mp;
  30.  
  31.     if( (fp = fopen(file,"rb")) == NULL )
  32.     return NULL;
  33.  
  34.     fseek(fp,0L,SEEK_END);
  35.     fsz = ftell(fp);
  36.     rewind(fp);
  37.  
  38.     if( (buf = malloc(fsz+4)) == NULL) {
  39.     fclose(fp);
  40.     return NULL;
  41.     }
  42.     *((int *)(&buf)) = *((int *)(&buf)) & 0xFFFFFFFC;
  43.     fread(buf,fsz,1,fp);
  44.     fclose(fp);
  45.  
  46.     return buf;
  47. }
  48. void    xclose(char *buf)
  49. {
  50.     free(buf);
  51. }
  52. void    PLAY_snd(file)
  53. char    *file;
  54. {
  55.     int     sw,x,y;
  56.     char    *snd_buf;
  57.  
  58.     if ( (snd_buf = xopen(file)) == NULL )
  59.     return;
  60.  
  61.     DSP_mos(3);
  62.  
  63.     SND_pcm_sound_delete(-1);
  64.     SND_pcm_mode_set(1);
  65.  
  66.     SND_pan_set(71,64);
  67.     *(int *)(snd_buf+20) = 0;
  68.     SND_pcm_play(71,snd_buf[28],127,snd_buf);
  69.  
  70.     while ( SND_pcm_status(71) ) {
  71.     MOS_rdpos(&sw,&x,&y);
  72.     if ( sw != 0 )
  73.         break;
  74.     }
  75.  
  76.     SND_pcm_play_stop(71);
  77.     SND_pcm_rec_stop();
  78.     xclose(snd_buf);
  79.  
  80.     DSP_mos(0);
  81. }
  82.  
  83. void    PLAY_eup(file)
  84. char    *file;
  85. {
  86.     int     i;
  87.     int     sw,x,y;
  88.     int     err,size,signa,tempo;
  89.     char    *p;
  90.     char    *eup_buf;
  91.     char    tmp[16];
  92.     char    dmy[16];
  93.     char    wrk[80];
  94.  
  95.     if( (eup_buf = xopen(file)) == NULL )
  96.     return;
  97.  
  98.     DSP_mos(4);
  99.  
  100.     SND_eup_init(swork);
  101.     SND_elevol_mute(0xB3);
  102.  
  103.     p = &eup_buf[852];        /* trk mute */
  104.     for( i = 0 ; i < 32 ; i++ )
  105.     err = SND_eup_mute_set(i,*(p++));
  106.  
  107.     p = &eup_buf[884];        /* trk port */
  108.     for( i = 0 ; i < 32 ; i++ )
  109.     err = SND_eup_port_set(i,*(p++));
  110.  
  111.     p = &eup_buf[916];        /* trk midi ch */
  112.     for( i = 0 ; i < 32 ; i++ )
  113.     err = SND_eup_midi_ch_set(i,*(p++));
  114.  
  115.     p = &eup_buf[948];        /* trk key bias */
  116.     for( i = 0 ; i < 32 ; i++ )
  117.     err = SND_eup_bias_set(i,*(p++));
  118.  
  119.     p = &eup_buf[980];        /* trk transpose */
  120.     for( i = 0 ; i < 32 ; i++ )
  121.     err = SND_eup_transpose_set(i,*(p++));
  122.  
  123. /********************
  124.     channel assign
  125. *********************/
  126.  
  127.     p = &eup_buf[1748];        /* fm midi ch */
  128.     for( i = 0 ; i < 6 ; i++ )
  129.     err = SND_midi_ch_assign(i,*(p++));
  130.  
  131.     p = &eup_buf[1754];        /* pcm midi ch */
  132.     for( i = 0 ; i < 8 ; i++ )
  133.     err = SND_midi_ch_assign(i+64,*(p++));
  134.  
  135. /****************
  136.     bank load
  137. *****************/
  138.  
  139.     SND_pcm_mode_set(0);
  140.  
  141.     strncpy(tmp,&eup_buf[1762],8);    /* fm file name */
  142.     tmp[8] = '\0';
  143.     if ( tmp[0] != '\0' ) {
  144.     strcat(tmp,".FMB");
  145.     strcpy(wrk,file);
  146.     if ( (p = strrchr(wrk,'\\')) != NULL ) {
  147.         strcpy(p+1,tmp);
  148.         p = wrk;
  149.     } else
  150.         p = tmp;
  151.     p = tmp;
  152.         if ( SND_fm_bank_load(p,dmy) != 0 ) {
  153.         if ( (p = getins("FMINST",tmp)) != NULL )
  154.          SND_fm_bank_load(p,dmy);
  155.     }
  156.     }
  157.  
  158.     strncpy(tmp,&eup_buf[1770],8);    /* pcm file name */
  159.     tmp[8] = '\0';
  160.     if ( tmp[0] != '\0' ) {
  161.     strcat(tmp,".PMB");
  162.     strcpy(wrk,file);
  163.     if ( (p = strrchr(wrk,'\\')) != NULL ) {
  164.         strcpy(p+1,tmp);
  165.         p = wrk;
  166.     } else
  167.         p = tmp;
  168.     p = tmp;
  169.         if ( SND_pcm_bank_load(p,dmy) != 0 ) {
  170.         if ( (p = getins("PCMINST",tmp)) != NULL )
  171.          SND_pcm_bank_load(p,dmy);
  172.     }
  173.     }
  174.  
  175. /*******************
  176.     play eup file
  177. ********************/
  178.  
  179.     p = &eup_buf[2048];        /* data top */
  180.     size = *((int *)p); p += 4;
  181.     signa = *(p++);
  182.     tempo = *(p++);
  183.  
  184.     SND_eup_loop_set(0);
  185.     SND_eup_tempo_set(tempo);
  186.     SND_eup_play_start(p,size,signa);
  187.  
  188.     while ( SND_eup_stat_flag() ) {
  189.     MOS_rdpos(&sw,&x,&y);
  190.     if ( sw != 0 )
  191.         break;
  192.     }
  193.  
  194.     SND_eup_play_stop();
  195.     SND_eup_end();
  196.     xclose(eup_buf);
  197.  
  198.     DSP_mos(0);
  199. }
  200.